package com.example.questionbase.controller;

import com.example.questionbase.pojo.User;
import com.example.questionbase.pojo.dto.UserDto;
import com.example.questionbase.service.UserService;
import com.example.questionbase.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 用户登录
     *
     * @param user
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        return userService.login(user);
    }

    /**
     * 添加用户
     *
     * @param user
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody User user) {
        return userService.add(user);
    }

    /**
     * 删除用户
     *
     * @param user
     * @return
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody User user) {
        return userService.delete(user);
    }

    /**
     * 更新用户
     *
     * @param user
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody UserDto user) {
        return userService.update(user);
    }


    /**
     * 分页查询用户
     * @param current
     * @param size
     * @param name
     * @return
     */
    @GetMapping("/page")
    public Result page(int current, int size, String name) {
        return userService.page(current,size,name);
    }

}
